package com.vini.core.dao;

import java.util.Iterator;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.vini.core.ec.Circles;
//import com.vini.core.ec.Travel;
import com.vini.core.ec.User;

@Repository
public class UserDaoImpl implements UserDao{
	
	@Autowired
	private SessionFactory sessionFactory;
	private Session session;

	@Override
	public User saveUser(User user) {
		try{
			session = sessionFactory.openSession();
			session.save(user);
			/*for(Travel travel : user.getTravels()){
				travel.setUser(user);
				session.save(travel);
			}
			for(Circle circle : user.getCircles()){
				circle.setCircleOwner(user);
				session.save(circle);
			}*/
			return user;
		}catch (Exception e) {
			e.printStackTrace();
			return null;
		}finally{
			session.close();
		}
	}

	@Override
	public User updateUser(User user) {
		try{
			session = sessionFactory.openSession();
			session.update(user);
			return user;
		}catch (Exception e) {
			e.printStackTrace();
			return null;
		}finally{
			session.close();
		}
	}

}
